import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import javax.xml.crypto.Data;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Test1 {
    public static void main(String[] args) throws SQLException {
        //1.创建DataSource
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource)dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/java109?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("0118");
        //2.建立连接
        Connection connection = dataSource.getConnection();
        //3.构造SQL
         String sql = "insert into class values(1 , '张三')";
        PreparedStatement statement = connection.prepareStatement(sql);

//        statement.executeQuery();   //读操作 ， select
       //4.把sql发给服务器
        int i =   statement.executeUpdate();  //写操作 ， insert ，update，delete
        System.out.println(i);
      //5.释放资源
        statement.close();
        connection.close();

    }
}
